package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController extends BaseController{

    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("获取所有护理计划")
    public ResponseResult<List<NursingPlanVo>> getAll(){
        List<NursingPlanVo> list = nursingPlanService.getAll();
        return success(list);
    }

    @PostMapping
    @ApiOperation("添加护理计划")
    public ResponseResult add(@ApiParam(value = "护理计划信息") @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.add(nursingPlanDto);
        return success();
    }

    @GetMapping("/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> page(
            @ApiParam(value = "计划名称") String name,
            @ApiParam(value = "页码", defaultValue = "1") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页数量", defaultValue = "10") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam(value = "状态") Integer status
    ){
        PageResponse<NursingPlanVo> list = nursingPlanService.page(name,pageNum,pageSize,status);
        return success(list);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取护理计划")
    public ResponseResult<NursingPlanVo> getById(@ApiParam(value = "计划ID") @PathVariable Integer id){
        NursingPlanVo nv = nursingPlanService.getById(id);
        return success(nv);
    }

    @PutMapping("/{id}")
    @ApiOperation("更新护理计划")
    public ResponseResult update(@ApiParam(value = "护理计划信息") @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据ID删除护理计划")
    public ResponseResult deleteById(@ApiParam(value = "计划ID") @PathVariable Integer id){
        nursingPlanService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("更新护理计划状态")
    public ResponseResult updateStatus(
            @ApiParam(value = "计划ID") @PathVariable Integer id,
            @ApiParam(value = "状态") @PathVariable Integer status
    ){
        nursingPlanService.updateStatus(id,status);
        return success();
    }
}